package com.adu.retrofixtest.config;

import com.adu.retrofixtest.service.RequestService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

@Configuration
public class RetrofitConfigure {
    @Value("${retrofit.baseUrl}")
    String baseUrl;

    @Bean
    public RequestService getRetrofitService(){
        //通过拦截器实现retrofit重试
        Retrofit retrofit=new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(GsonConverterFactory.create()).build();
        //动态代理模式创建请求接口的实例
        RequestService service=retrofit.create(RequestService.class);
        return service;
    }

}
